<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color: black;


        }
    </style>
</head>

<body>
    <button>开灯</button>
    <script>
        var btn = document.querySelector('button')
        var by = document.body
        var flgs = 0
        btn.onclick = function () {

            if (flgs === 0) {
                by.style.backgroundColor = 'white'
                btn.innerHTML='关灯'
                btn.style.color='black'
                btn.style.backgroundColor='springgreen'
                flgs = 1;
            } else if(flgs === 1)  {
                by.style.backgroundColor = 'red'
                btn.innerHTML='开灯'
                btn.style.backgroundColor='royalblue'
                flgs = 2;
            }else{
                by.style.backgroundColor = 'black'
                btn.innerHTML='关灯'
                btn.style.backgroundColor='green'
                flgs = 0;
            }
        }
    </script>
</body>

</html>